package com.spring.application;

import com.spring.entity.Person;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringApplication {

    @Test
    public void getBean(){
        //ApplicationContext 代表IOC容器
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf.xml");
        //容器帮助我们创建了对象
        Person person1 = context.getBean("person01", Person.class);
        Person person2 = context.getBean("person01", Person.class);
        System.out.println(person1 == person2);
    }

    @Test
    public void getBeanTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf.xml");
        Person pserson01 = context.getBean("person01", Person.class);
        System.out.println(pserson01);
        Person person = context.getBean(Person.class);
        System.out.println(person);
    }
    //从构造器中获取
    @Test
    public void getBeanConstruct(){
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf.xml");
        Person person = context.getBean("person02", Person.class);
        System.out.println(person);
    }

    //p 命名空间
    @Test
    public void getBeanP(){
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf.xml");
        Person person = context.getBean("person03", Person.class);
        System.out.println(person);
    }

}
